//
//  GDBaseViewController.m
//  GuiderHealth
//
//  Created by mo on 2020/8/13.
//  Copyright © 2020 YM&EF. All rights reserved.
//

#import "GDBaseViewController.h"
#import "BaseCategoryKit.h"
@interface GDBaseViewController ()

@end

@implementation GDBaseViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
//    [SVProgressHUD dismiss];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.hidden = YES;
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self.view addSubview:self.customNavBar];
    
    if (self.navigationController.childViewControllers.count != 1) {
        [self.customNavBar wr_setLeftButtonWithImage:[self gdBaseimageForBundle:@"BaseToolKit_TintColor"]];
    }
    [WRNavigationBar wr_setBlacklist:@[
                                       @"TZImagePickerController",
                                       @"TZGifPhotoPreviewController",
                                       @"TZAlbumPickerController",
                                       @"TZPhotoPreviewController",
                                       @"TZVideoPlayerController",
                                       @"TZPhotoPickerController",
                                       ]];
}

- (WRCustomNavigationBar *)customNavBar{
    if (_customNavBar == nil) {
        _customNavBar = [WRCustomNavigationBar CustomNavigationBar];
        if ([GetMainDeviceType isEqualToString:@"ALL"]||
            [GetMainDeviceType isEqualToString:@"GUIDERHEALTH"]||
            [GetMainDeviceType isEqualToString:@"Z800"]) {
            _customNavBar.barBackgroundImage = [self gdBaseimageForBundle:@"BaseToolKit_BackgroundImageBlue"];
        }else{
        _customNavBar.barBackgroundImage = [self gdBaseimageForBundle:@"BaseToolKit_BackgroundImage"];
        }
    }
    return _customNavBar;
}
- (void)setBackgroundColorIsOrange:(BOOL)isOrange{
    if (isOrange) {
        _customNavBar.barBackgroundImage = [self gdBaseimageForBundle:@"BaseToolKit_BackgroundImage"];
    }else{
        _customNavBar.barBackgroundImage = [self gdBaseimageForBundle:@"BaseToolKit_BackgroundImageBlue"];
    }
}

- (UIImage *)gdBaseimageForBundle:(NSString *)imageName
{
    NSBundle *resourceBundle = [self gdBaseResourceBundle];
    UIImage *image = [UIImage imageNamed:imageName
                                inBundle:resourceBundle
           compatibleWithTraitCollection:nil];
    
    return image;
}

- (NSBundle *)gdBaseResourceBundle
{
    NSBundle *bundle = [NSBundle bundleForClass:NSClassFromString(@"GDBaseViewController")];
    NSString *bundleName = bundle.infoDictionary[@"CFBundleName"];
    NSURL *bundleURL = [bundle URLForResource:bundleName withExtension:@"bundle"];
    if (!bundleURL) {
        bundleName = @"BaseToolsKit";
        bundleURL = [bundle URLForResource:bundleName withExtension:@"bundle"];
    }
    NSBundle *resourceBundle = [NSBundle bundleWithURL:bundleURL];
    return resourceBundle;
}


- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
    NSLog(@"//        %@   ->dealloc   //",NSStringFromClass([self class]));
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];//即使没有显示在window上，也不会自动的将self.view释放。
    // Add code to clean up any of your own resources that are no longer necessary.
    // 此处做兼容处理需要加上ios6.0的宏开关，保证是在6.0下使用的,6.0以前屏蔽以下代码，否则会在下面使用self.view时自动加载viewDidUnLoad
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0) {
        //需要注意的是self.isViewLoaded是必不可少的，其他方式访问视图会导致它加载 ，在WWDC视频也忽视这一点。
        // 是否是正在使用的视
        if (self.isViewLoaded && !self.view.window){
            self.view = nil;// 目的是再次进入时能够重新加载调用viewDidLoad函数。
        }
    }
}

@end
